/**
 * 题目： 字符串中划线转驼峰式
 * 输入： 'this-is-a-selector'
 * 输出： 'thisIsASelector'
 * 测试： camelize('this-is-a-selector') === 'thisIsASelector'
 */ 
function camelize(str) {
  // 分割字符串
  const camelizeArray = str.split('-')
  // 遍历 转首字母大写
  const result = []
  for (let index = 0; index < camelizeArray.length; index++) {
    const element = camelizeArray[index]
    if (index === 0) {
      result.push(element)
    } else {
      let word = []
      for (let index = 0; index < element.length; index++) {
        if (index === 0) {
          // 转大写
          word.push(element[index].toUpperCase())
        } else {
          word.push(element[index])
        }
      }
      result.push(word.join(''))
    }
  }
  return result.join('')
}
console.log(camelize('this-is-a-selector'))
console.log(camelize('this-is-a-selector') === 'thisIsASelector')

/**
 * 题目：找出字符串字母出现次数
 * 输入： 'abc,abc,aaa'
 * 输出： {a:5, b:2, c:2, ',':2}
 * 测试： console.log(find('abc,abc,aaa'))
 */
function find(string) {
  // 直接遍历 把结果放到对象里面
  const chars = {}
  for (let index = 0; index < string.length; index++) {
    const element = string[index];
    if (chars[element]) {
      chars[element]++
    } else {
      chars[element] = 1
    }
  }
  return chars
}
console.log(find('abc,abc,aaa'))

/**
 * 题目: 手机号加密
 * 输入：15929485138, '*', 3, 4 从第3位开始的后4位替换为*
 * 输出: 159****5138
 * 测试: console.log(secretMobile(15929485138, 3, 4, '*'))
 */
function secretMobile(mobile, start, length, symbol) {
  // 直接遍历
  const mobileString = mobile.toString()
  const result = []
  for (let index = 0; index < mobileString.length; index++) {
    if (index >= start && index < start + length) {
      result.push(symbol)
    } else {
      result.push(mobileString[index])
    }
  }
  return result.join('')
}
console.log(secretMobile(15929485138, 3, 4, '*'))
